package com.tianyi.sfzy1.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Psychologyknowledge;
import com.tianyi.sfzy1.service.PsychologykonwledgeService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("paychologyknoeledge")
public class PsychologyknowledgeController {
    @Autowired
    PsychologykonwledgeService psychologykonwledgeService;

    @PostMapping
    public R add( Psychologyknowledge psychologyknowledge){
        int i=psychologykonwledgeService.addPsychologyknowledge(psychologyknowledge);
        if(i>0){
            return R.ok(null);
        }
        else{
            return R.fail("添加失败");
        }
    }
//    @GetMapping
//    public R getAll(){
//        List<Psychologyknowledge> list =psychologykonwledgeService.getAllPsychologyknowledge();
//        return R.ok(list);
//    }
//    终极版全和了 模糊查询
@GetMapping
public R getAll(Psychologyknowledge record,int pageNum,int pageSize){
    System.out.println(record);
    PageInfo<Psychologyknowledge> list=psychologykonwledgeService.getAllPsychologyknowledge(record,pageNum,pageSize);
    return R.ok(list);
}
    @DeleteMapping("/id")
    public R deleteById(Long id){
        int i = psychologykonwledgeService.deletePsychologyknowledge(id);
        if(i>0){
            return R.ok(null);
        }
        else{
            return R.fail("删除失败");
        }

    }
//删除多个
    @DeleteMapping
    public R deleteMany(@RequestBody List<Integer> ids){
        int i=psychologykonwledgeService.deleteManyPsychologyknowledge(ids);
        if(i>0){
            return R.ok(null);
        }
        else{
            return R.fail("删除失败");
        }
    }
//    部分修改
    @PutMapping
    public R updateSelective( Psychologyknowledge psychologyknowledge){
        System.out.println(psychologyknowledge);
        int i=psychologykonwledgeService.updateSelectivePsychologyknowledge(psychologyknowledge);
        if(i>0){
            return R.ok(null);
        }
        else{
            return R.fail("修改失败");
        }

    }
////    模糊查询
//    @GetMapping("/search")
//    public R search(Psychologyknowledge record){
//        List<Psychologyknowledge> list = psychologykonwledgeService.searchPsychologyknowledge(record);
//        return R.ok(list);
//    }


}
